Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Encode and parse data in the Concise Binary Object Representation (CBOR) data format (RFC7049).
The 'borc' npm package is a JavaScript library for encoding and decoding data in the CBOR (Concise Binary Object Representation) format. CBOR is a binary data serialization format similar to JSON but more compact, making it suitable for data exchange in constrained environments.
Encoding Data to CBOR
This feature allows you to encode JavaScript objects into the CBOR format. The code sample demonstrates encoding a simple object with a key-value pair into CBOR.
const cbor = require('borc');
const encoded = cbor.encode({ key: 'value' });
console.log(encoded);
Decoding CBOR Data
This feature allows you to decode CBOR data back into JavaScript objects. The code sample shows how to decode previously encoded CBOR data back into its original object form.
const cbor = require('borc');
const encoded = cbor.encode({ key: 'value' });
const decoded = cbor.decode(encoded);
console.log(decoded);
Streaming Decoding
This feature provides the ability to decode CBOR data from a stream, which is useful for processing large datasets or data received over a network. The code sample demonstrates setting up a stream decoder and processing encoded data.
const cbor = require('borc');
const { Decoder } = cbor;
const decoder = new Decoder();
decoder.on('data', (data) => console.log(data));
decoder.write(cbor.encode({ key: 'value' }));
The 'cbor' package is another popular library for encoding and decoding CBOR data in JavaScript. It offers similar functionality to 'borc' but is often noted for its performance optimizations and additional features like support for custom tags. Compared to 'borc', 'cbor' might be preferred for applications requiring high performance or specific CBOR features.
The 'cbor-js' package is a lightweight CBOR encoder/decoder for JavaScript, designed to work in both Node.js and browser environments. It is simpler and smaller than 'borc', making it suitable for projects where minimizing bundle size is important. However, it may lack some of the advanced features and optimizations found in 'borc'.
Assimilate all your JavaScript objects into the Concise Binary Object Representation (CBOR) data format (RFC7049) as fast as possible.
This library is a fork of the awesome node-cbor. It borrows a lot of the interface, but drops all streaming and async processing in favor of a minimal syn api and being as fast as possible.
$ npm install --save borc
TODO
const cbor = require('borc')
const assert = require('assert')
const encoded = cbor.encode(true) // returns <Buffer f5>
const decoded = cbor.decodeFirst(encoded)
// decoded is the unpacked object
assert.ok(decoded === true)
// Use integers as keys
var m = new Map()
m.set(1, 2)
encoded = cbor.encode(m) // <Buffer a1 01 02>
See https://dignifiedquire.github.io/borc for details
The sync encoding and decoding are exported as a
leveldb encoding, as
cbor.leveldb
.
The following types are supported for encoding:
Decoding supports the above types, including the following CBOR tag numbers:
Tag | Generated Type |
---|---|
0 | Date |
1 | Date |
2 | bignumber |
3 | bignumber |
4 | bignumber |
5 | bignumber |
32 | url.URL |
35 | RegExp |
Borc supports custom tags as well as custom input types.
class MyType {
constructor (val) {
this.val = val
}
// Gets called when encoding this object
// gen - instance of the encoder
// obj - the object being encoded
//
// should return true on success and false otherwise
encodeCBOR (gen) {
return gen.pushAny('mytype:' + this.val)
}
}
cbor.encode([new MyType('hello')])
cbor.encode([new cbor.Tagged(42, 'hello')])
const decoder = new cbor.Decoder({
tags: {
42: (val) => val + ' world'
}
})
MIT
FAQs
Encode and parse data in the Concise Binary Object Representation (CBOR) data format (RFC7049).
The npm package borc receives a total of 131,026 weekly downloads. As such, borc popularity was classified as popular.
We found that borc demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.